/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Blackjack;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JOptionPane;

/**
 *
 * @author Red
 */
public class DataManagerSesion {

    public DataManagerSesion() {

    }

    public SesionBkjk cargarSesion(String path) {
        SesionBkjk sesion = null;
        try {
            ObjectInputStream o = new ObjectInputStream(new FileInputStream(path));
            sesion = (SesionBkjk)o.readObject();
            o.close();
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null,
            "No se ha podido cargar la partida, o la partida indicada no existe.",
            "Inane warning",
            JOptionPane.WARNING_MESSAGE);
        }
        return sesion;
    }

    public SesionBkjk guardarSesion(String path, SesionBkjk sesion) {
        try {
            ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(path));
            o.writeObject(sesion);
            o.close();
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null,
            "No se ha podido borrar la partida, o la partida indicada no existe.",
            "Inane warning",
            JOptionPane.WARNING_MESSAGE);
        }
        return sesion;
    }

    public void borrarSesion(String path) {
        if (!(new File(path).delete())) {
            JOptionPane.showMessageDialog(null,
            "No se ha podido borrar la partida, o la partida indicada no existe.",
            "Inane warning",
            JOptionPane.WARNING_MESSAGE);
        }
    }
}
